<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="商户名称" prop="lesseeName">
        <el-input
          v-model="queryParams.lesseeName"
          placeholder="请输入商户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法人名称" prop="signName">
        <el-input
          v-model="queryParams.signName"
          placeholder="请输入法人名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法人身份证号" prop="identityCard">
        <el-input
          v-model="queryParams.identityCard"
          placeholder="请输入法人身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系方式" prop="lesseePhone">
        <el-input
          v-model="queryParams.lesseePhone"
          placeholder="请输入联系方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="注册地址" prop="lesseeAddr">
        <el-input
          v-model="queryParams.lesseeAddr"
          placeholder="请输入注册地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="付费模式" prop="lesseePolicy">
        <el-input
          v-model="queryParams.lesseePolicy"
          placeholder="请输入付费模式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审批通过时间" prop="approvalTime">
        <el-date-picker clearable
          v-model="queryParams.approvalTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择审批通过时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="到期时间" prop="endTime">
        <el-date-picker clearable
          v-model="queryParams.endTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择到期时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="状态" prop="state">
        <el-input
          v-model="queryParams.state"
          placeholder="请输入状态"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="lesseeList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="商户编号" align="center" prop="lesseeId" />
      <el-table-column label="商户名称" align="center" prop="lesseeName" />
      <el-table-column label="法人名称" align="center" prop="signName" />
      <el-table-column label="法人身份证号" align="center" prop="identityCard" />
      <el-table-column label="联系方式" align="center" prop="lesseePhone" />
      <el-table-column label="注册地址" align="center" prop="lesseeAddr" />
      <el-table-column label="付费模式" align="center" prop="lesseePolicy" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审批通过时间" align="center" prop="approvalTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.approvalTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="到期时间" align="center" prop="endTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="state" >
        <template slot-scope="scope">
          <span v-if="scope.row.state==0">待审批</span>
          <span v-if="scope.row.state==1" style="color: lawngreen">管理员审批通过</span>
          <span v-if="scope.row.state==2" style="color: red">管理员审批不通过</span>
          <span v-if="scope.row.state==3" style="color: lawngreen">财务审批通过</span>
          <span v-if="scope.row.state==4" style="color: red">财务审批不通过</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['lessee:lessee:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['lessee:lessee:remove']"
          >删除</el-button>

          <el-button
            size="mini"
            type="text"
            v-if="scope.row.state==1"
            @click="approvalupdate(scope.row)"
          >审批</el-button>

        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />



    <!-- 审批详细信息话框 -->
    <el-dialog  title="审批详细信息" :visible.sync="dialogFormVisible">
      <el-form :model="lessee" :inline="true">
        <el-form-item  label="商户名称" style="width: 30%;">
          <el-input v-model="lessee.lesseeName"/>
        </el-form-item>
        <el-form-item label="法人姓名" style="width: 30%;">
          <el-input v-model="lessee.signName"/>
        </el-form-item>
        <el-form-item label="法人身份证" style="width: 30%;">
          <el-input v-model="lessee.identityCard" />
        </el-form-item>
        <el-form-item label="练习方式" style="width: 30%;">
          <el-input v-model="lessee.lesseePhone"/>
        </el-form-item>
        <el-form-item label="注册地址" style="width: 30%;">
          <el-input v-model="lessee.lesseeAddr"/>
        </el-form-item>
        <el-form-item label="审批状态" style="width: 30%;">
          <el-input v-model="lessee.state">
              <span v-if="lessee.state==0">待审批</span>
              <span v-if="lessee.state==1">管理员审批通过</span>
              <span v-if="lessee.state==2">管理员审批不通过</span>
              <span v-if="lessee.state==3">财务审批通过</span>
              <span v-if="lessee.state==4">财务审批不通过</span>
          </el-input>

        </el-form-item>
      </el-form>
      <span>-------------------------------------------------</span>

        <el-form :model="data">
        <el-form-item label="公司名称" style="width: 30%;">
          <el-input v-model="data.companyName"/>
        </el-form-item>
        <el-form-item label="营业执照图片" style="width: 30%;">
          <el-image
            style="width: 100px; height: 100px"
            :src="data.businessLicense"
          >
          </el-image>
        </el-form-item>
        <el-form-item label="身份证正面照" style="width: 30%;">
          <el-image
            style="width: 100px; height: 100px"
            :src="data.idIs"
            >
          </el-image>
        </el-form-item>
        <el-form-item label="身份证反面照" style="width: 30%;">
            <el-image
              style="width: 100px; height: 100px"
              :src="data.idThe"
              >
            </el-image>
<!--          <el-input v-model="data.idThe"/>-->
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" v-hasPermi="['lessee:lessee:edit']"  @click="pass">通 过</el-button>
        <el-button @click="reject">驳 回</el-button>
      </div>
    </el-dialog>



    <!-- 添加或修改商户列表对话框 -->
<!--    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="商户名称" prop="lesseeName">
          <el-input v-model="form.lesseeName" placeholder="请输入商户名称" />
        </el-form-item>
        <el-form-item label="法人名称" prop="signName">
          <el-input v-model="form.signName" placeholder="请输入法人名称" />
        </el-form-item>
        <el-form-item label="法人身份证号" prop="identityCard">
          <el-input v-model="form.identityCard" placeholder="请输入法人身份证号" />
        </el-form-item>
        <el-form-item label="联系方式" prop="lesseePhone">
          <el-input v-model="form.lesseePhone" placeholder="请输入联系方式" />
        </el-form-item>
        <el-form-item label="注册地址" prop="lesseeAddr">
          <el-input v-model="form.lesseeAddr" placeholder="请输入注册地址" />
        </el-form-item>
        <el-form-item label="付费模式" prop="lesseePolicy">
          <el-input v-model="form.lesseePolicy" placeholder="请输入付费模式" />
        </el-form-item>
        <el-form-item label="审批通过时间" prop="approvalTime">
          <el-date-picker clearable
            v-model="form.approvalTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择审批通过时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="到期时间" prop="endTime">
          <el-date-picker clearable
            v-model="form.endTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择到期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="状态" prop="state">
          <el-input v-model="form.state" placeholder="请输入状态" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>-->
  </div>
</template>

<script>
import { listLessee, getLessee, delLessee, addLessee, updateLessee } from "@/api/lessee/lessee";
import {listData} from "@/api/data/data";
import Cookies from "js-cookie";
import ScrollPane from "@/layout/components/TagsView/ScrollPane";

export default {
  name: "Lessee",
  components: {ScrollPane},
  data() {
    return {
      lessee:{},
      data:{
        companyName:'',
        businessLicense:'',
        idIs:'',
        idThe:''
      },
      dialogFormVisible:false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商户列表表格数据
      lesseeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        lesseeName: null,
        signName: null,
        identityCard: null,
        lesseePhone: null,
        lesseeAddr: null,
        lesseePolicy: null,
        approvalTime: null,
        endTime: null,
        state: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      appraoval:{
        lesseeId:'',
        state:''
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /*驳回*/
    reject(){
      this.appraoval.lesseeId=this.lessee.lesseeId
      this.appraoval.state=3
      updateLessee(this.appraoval).then(resp=>{
        this.$message.success("已驳回")
        this.dialogFormVisible=false;
        this.getList()
      })
    },


    /*审批*/
    pass(){
      this.appraoval.lesseeId=this.lessee.lesseeId
      this.appraoval.state=3
      updateLessee(this.appraoval).then(resp=>{
        this.$message.success("审批成功")
        this.dialogFormVisible=false;
        this.getList()
      })
    },

    /*打开审批页面*/
    approvalupdate(row){
      this.lessee=row
      this.dialogFormVisible=true

      listData(this.lessee.lesseeId).then(resp=>{
        this.data=resp.rows[0];
      })
    },
    /** 查询商户列表列表 */
    getList() {
      this.loading = true;
      listLessee(this.queryParams).then(response => {
        this.lesseeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        lesseeId: null,
        lesseeName: null,
        signName: null,
        identityCard: null,
        lesseePhone: null,
        lesseeAddr: null,
        lesseePolicy: null,
        createTime: null,
        approvalTime: null,
        endTime: null,
        state: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.lesseeId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加商户列表";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const lesseeId = row.lesseeId || this.ids
      getLessee(lesseeId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改商户列表";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.lesseeId != null) {
            updateLessee(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addLessee(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const lesseeIds = row.lesseeId || this.ids;
      this.$modal.confirm('是否确认删除商户列表编号为"' + lesseeIds + '"的数据项？').then(function() {
        return delLessee(lesseeIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('lessee/lessee/export', {
        ...this.queryParams
      }, `lessee_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
